<?php

namespace app\index\controller;

/**
 * Description of GroupAdmin
 * 分组管理
 * @author Dongasai
 */
class GroupAdmin extends \think\Controller
{

    /**
     *
     */
    public function index()
    {
        //读取分组信息
        $page  = input('page', 1, 'int');
        $low   = 10;
        $where = [
            'user_id' => session('uid')
        ];
        $order = '';
        $data  = \app\index\service\Group::lists($where, $order, $page, $low);

        $this->assign('group', dataToPagedata($data));
        return $this->fetch();
    }

    public function add()
    {
        if (request()->ispost()) {
            //处理数据
            $uid  = session('uid');
            $name = input("name", '', 'string');
            $re   = \app\index\service\Group::add($uid, $name);
            if (is_string($re)) {
                return $this->error($re);
            } else {
                return $this->success("成功!");
            }
        } else {
            //展示
            return $this->fetch();
        }
    }

}
